package com.fit.hibernate;

import java.io.Serializable;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.Session;

import com.fit.beans.ServiceBean;
import com.fit.interfaces.ServiceI;
import com.fit.service.ServicesI;

public class ServiceHibernate implements ServicesI {

	private Session session;
	
	
	
	public ServiceHibernate(Session session) {
		this.session = session;
	}

	@Override
	public ServiceI save(ServiceI service) {
		
		return (ServiceI) session.get(ServiceBean.class, session.save(service));
	}

	@Override
	public Collection<ServiceI> retrive() {
		Criteria criteria = session.createCriteria(ServiceBean.class);
		return criteria.list();
	}

	@Override
	public ServiceI editSingleService(ServiceI service) {
		// TODO Auto-generated method stub
		return (ServiceI) session.merge(service);
	}

	@Override
	public ServiceI retriveSingleService(Serializable id) {
		// TODO Auto-generated method stub
		return (ServiceI) session.get(ServiceBean.class, id);
	}

}
